/**
 * 设置线程优先级
 */
public class ThreadDemoByPriority2 {
    private final static int MAXCOUNT=1000;
    public static void main(String[] args) {
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                Thread t=Thread.currentThread();
                int priority=t.getPriority();
                for (int i = 0; i <MAXCOUNT ; i++) {
                    System.out.println(t.getName()+"--优先级:"+priority);
                }
            }
        },"线程1");
        //t1.setPriority(10);
        //设置线程优先级
        t1.setPriority(Thread.MAX_PRIORITY);

        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                Thread t=Thread.currentThread();
                int priority=t.getPriority();
                for (int i = 0; i <MAXCOUNT ; i++) {
                    System.out.println(t.getName()+"--优先级:"+priority);
                }
            }
        },"线程2");
        t2.setPriority(Thread.MIN_PRIORITY);

        Thread t3=new Thread(new Runnable() {
            @Override
            public void run() {
                Thread t=Thread.currentThread();
                int priority=t.getPriority();
                for (int i = 0; i <MAXCOUNT ; i++) {
                    System.out.println(t.getName()+"--优先级:"+priority);
                }
            }
        },"线程3");
        t3.setPriority(Thread.NORM_PRIORITY);

        //同时启动线程
        t2.start();
        t1.start();
        t3.start();
    }
}
